package com.applet.utils.common;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2018/4/20.
 */
public class DateUtil {

    public static void main(String[] args){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH");//时间格式精确到小时

        String time = getTime("2018-03-26(明天) 0");
        /*String str = ",0,1,3,d32e81581998496680d4e500ba47e46d,";
        String msg = getClassType(str);*/
        System.out.print("解析的时间格式："+time);

        /*SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try{
            Date createTime=sdf.parse("2018-04-23 10:00:00");
            long day = getDateByMin(createTime,new Date());
            //String day = getEndDate(new Date(),25);

            System.out.print("时间格式:"+day);

        }catch (Exception e){
            e.getStackTrace();
        }*/

    }

    public static String getTime(String time){

        String day = time.substring(0,10);
        int i = time.indexOf(")");

        String min=time.substring(i+1,time.length());

        return day+" "+min;
    }

    /**
     * 解析时间格式
     * @param time
     * @return
     */
    public static String showTime(String time){

        String day = time.substring(0,10);
        String min=time.substring(time.length()-5,time.length());

        return day+" "+min;
    }

    /**
     * 求本地时间与创建时间差 分钟
     * @param createTime  开始时间
     * @param nowTime     系统本地时间
     * @return
     */
    public static long getDateByMin(Date createTime,Date nowTime){
        long day=0;
        try{
            day=(nowTime.getTime()-createTime.getTime())/(60*1000);
        }catch (Exception e){
            e.getStackTrace();
        }
        return day;
    }

    /**
     * 创建时间+有效分钟
     * @param createTime
     * @param validPeriod
     * @return
     */

    public static String getEndDate(Date createTime,long validPeriod){
        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long time = createTime.getTime()+(validPeriod*(60*1000));
        Date date =new Date(time);

        return sdf.format(date);
    }

    public static String getClassType(String str){

        String [] obj = str.split(",");


        return obj[3];
    }



}
